<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建及下载二进制文件</title>
    <style>
        textarea{
            width: 400px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div>
        <textarea id="text" placeholder="请输入一些文字"></textarea>
    </div>
    <button onclick="download()">下载</button>
    <script>
        function download () {
            const text = document.getElementById('text').value;
            const blob = new Blob([JSON.stringify(text, null, 2)]);
            const  a = document.createElement('a');
            const url = URL.createObjectURL(blob);
            a.download = 'test.txt';
            a.href = url;
            a.click();
            a.remove();
        }
    </script>
</body>
</html>